<%--@elvariable id="dictName" type="java.lang.String"--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <%@include file="../../includes/common.jsp" %>
    <title><spring:message code="dictValues"/></title>
<body>
<div id="mainContent" class="easyui-panel" data-options="fit:true" style="padding: 10px">
    <form class="form-inline">
        账号<input type="text" name="loginName" id="loginName" value=""/>
        性别<input type="text" name=showSex id="showSex" value="" class="input-medium" flag="sex" autocomplete="off"/>
                <input type="hidden" name="sex" id="sex"  autoHidden="autoHidden">
        <a class="btn btn-primary" onclick="query()"><spring:message code="query"/></a>
        <a class="btn btn-primary" onclick="delConsumer()"><spring:message code="delete"/></a>
    </form>
    <table id="dataTable"></table>
    <div id="dataEdit" closed="true" modal="true" style="overflow: hidden">
        <iframe style="width: 100%;height: 100%" id="contentList" name="contentList" marginheight="0" marginwidth="0"
                frameborder="0" src="" allowTransparency="true">
        </iframe>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    function query() {
        listOption.url = basePath + "admin/user/listAllUser";
        listOption.data = "loginName=" + $("#loginName").val().trim() + "&showSex=" + $("#sex").val();
        listOption.pageNumber = 1;
        loadData(listOption);
    }

    function initDataGrid() {
        $('#dataTable').datagrid({
            title:'用户列表',
            pagination: true,
            fitColumns: true,
            columns: [
                [
                    {field: 'id', title: "&nbsp;<input id='checkAll' type='checkbox' onclick='selectAll()'/>", align: 'center', width: 50},
                    {field: 'loginName', title: '用户名', sortable: true, align: 'center', width: 150},
                    {field: 'showSex', title: '性别', sortable: true, align: 'center', width: 100},
                    {field: 'birthday', title: '生日', align: 'center', width: 200},
                    {field: 'email', title: '邮箱', align: 'center', width: 100},
                    {field: 'city', title: '城市', align: 'center', width: 100}
                ]
            ],
            sortName: "",
            sortOrder: "asc",
            onSortColumn: onSortColumn
        });
    }

    function onSortColumn(sortColumn, sortDirection) {
        switch (sortColumn) {
            case "dictCode":
                sortColumn = "dict_code";
                break;
            case "dictValue":
                sortColumn = "dict_value";
                break;
        }
        onSortColumnDefault(sortColumn, sortDirection);
    }

    function format(data) {
        data.resultList = queryFormat(data.resultList);
        return data;
    }
    function queryFormat(temp) {
        var rowDataList = [];
        for (var i in temp) {
            idBtn = "&nbsp;<input type='checkbox' name='deleteUserCheckBox' id='" + temp[i].id + "' value='" + temp[i].id + "'\">&nbsp;";
            editBtn = "&nbsp;<a onclick='user.edit(\"" + temp[i].id + "\")'><spring:message code="edit"/></a>&nbsp;";
            temp[i].id = idBtn;
            temp[i].edit = editBtn;
            rowDataList.push(temp[i]);
        }
        return rowDataList;
    }

    var user = {
        edit: function (id) {
            $("#contentFrame")[0].contentWindow.document.write("");
            $("#contentFrame").attr("src", basePath + "admin/user/editAdministratorDo?id=" + id);
            $('#dataEdit').dialog({
                title: '<spring:message code="edit"/>',
                height: 400,
                width: 600
            })
            $('#dataEdit').dialog('open');
        }
    };

    function delConsumer() {
        var ids = "";
        var value;
        var flag = 0;
        var allBox = $("[name='deleteUserCheckBox']");
        for (var i = 0; i < allBox.length; i++) {
            value = allBox[i].getAttribute("value");
            if ($("#" + value).attr("checked") == "checked") {
                flag = 1;
                ids += value + ",";
            }
        }
        if (flag == 0) {
            $.messager.alert("<spring:message code="prompt"/>", "<spring:message code="selectDeleteUser"/>");
            return;
        }
        $.messager.confirm("<spring:message code="prompt"/>", "<spring:message code="ensureDelete"/><spring:message code="questionMark"/>", function (r) {
            if (r) {
                $.ajax({
                    url: basePath + "admin/user/delAdministrator?ids=" + ids,
                    dataType: "json",
                    type: "DELETE",
                    success: function () {
                        $.messager.alert("<spring:message code="succeed"/>", "<spring:message code="deleteSucceed"/><spring:message code="exclamationMark"/>", "", function () {
                            query();
                        })
                    },
                    error: doError
                })
            }
        })
        }
    function selectAll() {
        if ($("#checkAll").attr("checked") == "checked") {
            $("[name='deleteUserCheckBox']").attr("checked", true);
        } else {
            $("[name='deleteUserCheckBox']").attr("checked", false);
        }
    }

    $(function () {
        initDataGrid();
        query();
    })
</script>